package com.xuecheng.media.controller;

import com.xuecheng.api.content.model.CourseBaseDTO;
import com.xuecheng.api.media.model.MediaAuditApi;
import com.xuecheng.api.media.model.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaAuditVO;
import com.xuecheng.common.domain.code.CommonErrorCode;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.entity.Media;
import com.xuecheng.media.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class MediaAudtoController implements MediaAuditApi {
    public static final Long OPERATION_FLAG = 1232141425l;
    @Autowired
    private MediaService mediaService;

    @PostMapping("/m/media/list")
    public PageVO queryMediaList4b(PageRequestParams params, @RequestBody QueryMediaModel model) {
        return mediaService.queryMediaList(params, model, null);
    }

    @PutMapping("m/media/audit")
    public void approveMedia(@RequestBody MediaAuditVO auditVO) {
        //将 vo 转为 dto 数据
        MediaDTO dto = MediaConvert.INSTANCE.voAuto2dto(auditVO);
        //调用service方法进行课程审核
        mediaService.approve(dto);
    }

    @Override
    @GetMapping("/m/media/preview/{mediaId}")
    public String getMediaUrl4b(@PathVariable Long mediaId) {
        return mediaService.getPlayUrlByMediaId(mediaId,1232141425l);
    }

    @GetMapping("/l/media/{mediaId}")
    RestResponse<MediaDTO> getById(@PathVariable Long mediaId){
        Media media = mediaService.getById(mediaId);
        MediaDTO mediaDTO = MediaConvert.INSTANCE.entity2dto(media);
        RestResponse<MediaDTO> response = new RestResponse();
        response.setCode(CommonErrorCode.SUCCESS.getCode());
        response.setMsg("哈喽");
        response.setResult(mediaDTO);
        return response;
    }

}
